﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyMainSite2.Data;
using MyMainSite2.Data.Repositories;
using MyMainSite2.UI.Web.Models.HomePage;

namespace MyMainSite2.UI.Web.Controllers
{
    public class HomePageController : Controller
	{
		#region Public Methods

		public ActionResult ProcessDynamicPage(string pageUrl)
		{
			if (String.IsNullOrWhiteSpace(pageUrl))
				return this.RedirectToAction("Error");

			var repo = PageRepositoryFactory.Repository;

			var page = repo.GetPageByUrl(pageUrl);
			if(page == null)
				return this.RedirectToAction("Error");

			var model = new DynamicPageModel()
			{
				Html = page.HTML,
				Title = page.Title,
			};

			return this.View(model);
		}

		public ViewResult Error()
		{
			return this.View();
		}

		#endregion
	}
}
